package pt.ist.meic.pava;

import javassist.*;



/**
 * 
 * @author Antonio Massingue
 * @author Joao Matos
 * @author Nuno Santos
 * 
 * Run!
 * 
 */
public class RunWithTraits {

	public static void main(String[] args){
		
		if(args.length < 1){
			System.out.print("Usage: RunWithTraits <class> [args]\n");
		}else{
		
			try {
				ClassPool pool = ClassPool.getDefault();
				Loader classLoader = new Loader(pool);
				Translator translator = new TraitTranslator(pool);
				
				classLoader.addTranslator(pool, translator);
				
				String[] restArgs = new String[args.length - 1];
				System.arraycopy(args, 1, restArgs, 0, restArgs.length);
				classLoader.run(args[0], restArgs);
				
			} catch (NotFoundException e) {
				System.out.println("Erro: Class not found");
				e.printStackTrace();
			} catch (CannotCompileException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
}
